/* 
 * File:   main.cpp
 * Author: andrea
 *
 * Created on October 28, 2013, 10:16 PM
 */

#include "../Headers/includes.h"


using namespace std;
using namespace cv;


Mat img, hsvImg;
Mat threshImg;
Mat threshImgHSV;
int matrixHalfSize = 4;

//callback function

void mouseCallback(int evt, int y, int x, int flags, void* data) {
    if (evt == EVENT_LBUTTONDOWN) {
        CUtilities util;
        CFiltering f;
        Vec3b median = util.computeMedianOddBGR(x, y, 9, img);
        f.thresholdFilteringBGR(50, median, img, threshImg);
        Vec3b medianHSV = util.computeMedianOddHSV(x, y, 9, hsvImg);
        f.thresholdFilteringHSV(50, 'H', Vec2b(medianHSV[0], medianHSV[1]), img, threshImgHSV);
        imshow("Thresholded Image", threshImg);
        imshow("Thresholded Image HSV", threshImgHSV);

    }
}

/*
 * 
 */
int main(int argc, char** argv) {

    //    CFiltering f;
    //
    //    // Open Image
    //    img = imread("/home/andrea/NetBeansProjects/ED3D/img/robocup.jpg");
    //    GaussianBlur(img, img, Size(33, 33), 1.1, 1.1);
    //    cvtColor(img,hsvImg,CV_BGR2HSV);
    //    namedWindow("Normal Image");
    //    imshow("Normal Image", img);
    //
    //    // HSV saturation
    //    Mat saturatedImg(img.rows, img.cols, CV_8UC3);
    //    namedWindow("Saturated Image");
    //    f.saturateHSV(100, img, saturatedImg, 'H');
    //
    //    // Object Segmentation: RGB
    //    threshImg = Mat(img.rows, img.cols, CV_8UC3);
    //    namedWindow("Thresholded Image");
    //    f.thresholdFilteringBGR(95, Vec3b(0, 128, 255), img, threshImg);
    //    
    //    
    //    // Object Segmentation: HSV
    //    threshImgHSV = Mat(img.rows,img.cols,CV_8UC3);
    //    cvtColor(img,threshImgHSV,CV_BGR2HSV);
    //    namedWindow("Thresholded Image HSV");
    //    f.thresholdFilteringHSV(50,'S',Vec2b(100,100),img,threshImgHSV);
    //
    //    setMouseCallback("Normal Image", mouseCallback);
    //
    //
    //    //    setMouseCallback("Normal Image", mouseCallback, 0);
    //    imshow("Thresholded Image", threshImg);
    //    imshow("Thresholded Image HSV", threshImgHSV);
    //    imshow("Saturated Image", saturatedImg);

    string path = "/home/andrea/NetBeansProjects/ED3D/img/calibration_resized/";
    Size boardSize(6, 8);

    Mat cameraMatrix, distCoeffs;
    vector<Mat> rotVecs, transVecs;
    CUtilities util;
    CCalibration cal;
    vector < vector < Point2f > > imagePoints = cal.findCornersFromDir(path, boardSize);

    vector<string> images = util.getFilesListFromDir(path);
    Mat oneRandomImage = imread(images[0]);
    Size imageSize(oneRandomImage.rows, oneRandomImage.cols);

    cal.calibrate(imagePoints, cameraMatrix, rotVecs, transVecs, distCoeffs, boardSize, imageSize);


    return 0;
}

